package struts.action;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.omg.CORBA.ARG_OUT;

import struts.utility.ParseXML;
import struts.utility.XMLBean;

/**
 * 监听器
 * 项目启动时，解析struts-config.xml配置文件
 * @author Administrator
 *
 */
public class ActionListener implements ServletContextListener {

	public ActionListener() {
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("信息：系统已注销！");
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		ServletContext context = arg0.getServletContext();
		String realPath=context.getRealPath("\\"); // D:\JavaDevelopEnvironment\JavaCode\mvc_2\WebContent\
		String xmlPath	=context.getInitParameter("struts-config"); // /WEB-INF/struts-config.xml
		String path = realPath + xmlPath; //  D:\JavaDevelopEnvironment\JavaCode\mvc_2\WebContent\/WEB-INF/struts-config.xml
		
		try {
			Map<String, XMLBean> map = ParseXML.parse(path); 
			context.setAttribute("strutsConfig", map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("信息：系统已经加载完成");
	}
}
